package com.zhang.stack;

import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.List;

public class SimpleStack<T> {

    class ZKStack<T> implements Cloneable{
       private int top;
       private List<T> content;
       private int maxSize;

       ZKStack(int size){
           top=-1;
           maxSize=size;
           content=new ArrayList(maxSize);
       }

        @Override
        protected Object clone() throws CloneNotSupportedException {
            return super.clone();
        }
    }

    private ZKStack zkStack;
    private int top;

    SimpleStack(int size){
        zkStack=new ZKStack(size);
        top=zkStack.top;
    }

    public void push(T value)
    {
        if (zkStack.maxSize-1==zkStack.top)
        {
            System.out.println("数据已满");
            return;
        }
        zkStack.content.add(value);
        zkStack.top++;
    }
    public T pop(){
        if (zkStack.top==-1)
        {
            throw new IllegalArgumentException("栈已空没有数据存在");
        }

    T value=(T) zkStack.content.get(zkStack.top);
      zkStack.top--;

        return value;
    }
    public void  view()
    {
        ZKStack zkStacks= null;
        try {
            zkStacks = (ZKStack) zkStack.clone();
        } catch (CloneNotSupportedException e) {
            e.printStackTrace();
        }
        while (zkStacks.top != -1)
        {
         System.out.println(zkStacks.content.get(zkStacks.top));
         zkStacks.top--;
      }
    }

}

class Test{
    public static void main(String[] a)
    {
        SimpleStack simpleStack=new SimpleStack(7);
        simpleStack.push(1);
        simpleStack.push(2);
        simpleStack.push(3);
        simpleStack.push(4);
        simpleStack.push(5);
        simpleStack.push(6);
        simpleStack.push(7);
        simpleStack.view();
        System.out.println("--------------------");
        simpleStack.pop();
        simpleStack.view();

    }
}